package edu.ucsd.cse135.gas.bean.reviewer;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class ReviewBean extends ActionForm {

	private String reviewer;
	private String applicant;
	private int graded;
	private int grade;
	private String comment;
	private String page;
	private String decision;
	
	public String getReviewer() {
		return reviewer;
	}
	public void setReviewer(String reviewer) {
		this.reviewer = reviewer;
	}
	public String getApplicant() {
		return applicant;
	}
	public void setApplicant(String applicant) {
		this.applicant = applicant;
	}
	public int getGraded() {
		return graded;
	}
	public void setGraded(int graded) {
		this.graded = graded;
	}
	public int getGrade() {
		return grade;
	}
	public void setGrade(int grade) {
		this.grade = grade;
	}
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getDecision() {
		return decision;
	}
	public void setDecision(String decision) {
		this.decision = decision;
	}
	
	public ActionErrors validation(ActionMapping mapping, HttpServletRequest request) {

		ActionErrors actionErrors = new ActionErrors();

		 if((page.equals("overview") || page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer")) 
				 && applicant != null && !applicant.contains("@")) 
		 {
	 		actionErrors.add("applicant", new ActionMessage("Form for applicant is invalid. It should be an e-mail address!"));
		 }
		 else if(page.equals("overview") || page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer"))
		 {
			 actionErrors.add("applicant", new ActionMessage("Applicant is required!"));
		 }
		 
		 if((page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer")) 
				 && reviewer != null && !reviewer.contains("@")) 
		 {
	 		actionErrors.add("reviewer", new ActionMessage("Form for reviewer is invalid. It should be an e-mail address!"));
		 }
		 else if(page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer"))
		 {
			 actionErrors.add("reviewer", new ActionMessage("Reviewer is required!"));
		 }
		 
		 if((page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer")) && grade == 0)
		 {
			 actionErrors.add("grade", new ActionMessage("Grade is required!"));
		 }
		 
		 if((page.equals("grading") || page.equals("complete") || page.equals("chooseReviewer")) && comment.isEmpty())
		 {
			 actionErrors.add("comment", new ActionMessage("Comment is required!"));
		 }

		return actionErrors;
	}


}